/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.*;
import java.util.stream.IntStream;

/**
 * <p>Project: javase - List5
 * <p>Powered by webrx On 2021-12-09 09:16:59
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class List5 {
    public static void main(String[] args) {
        List<Integer> list = new ArrayList<>();
        list.addAll(List.of(1, 6, 3, 20, 9, 5));
        //数字
        System.out.println(list);
        Collections.sort(list);
        list.sort((a, b) -> b - a); //降序
        System.out.println(list);
        list.sort((a, b) -> a - b); //升序
        System.out.println(list);
        Collections.shuffle(list); //乱序
        System.out.println(list);

        list = randomList((ArrayList) list);
        System.out.println(list);
        //字符串

        //对象
    }

    public static ArrayList randomList(ArrayList sourceList) {
        if (sourceList == null || sourceList.size() == 0) {
            return sourceList;
        }
        ArrayList randomList = new ArrayList(sourceList.size());
        do {
            int randomIndex = Math.abs(new Random().nextInt(sourceList.size()));
            randomList.add(sourceList.remove(randomIndex));
        } while (sourceList.size() > 0);
        return randomList;
    }

}
